{% extends 'AdminBundle::layout.html.twig' %}

    {% block title %}文件列表{% endblock %}

    {% block css %}
        <link type="text/css" rel="stylesheet" href="{{ asset('assets/css/bootstrap-datetimepicker.min.css') }}">
    {% endblock %}





{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}


    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}


    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">文件管理</span>
            </div>
            <div class="top-nav top-nav-active">文件列表</div>
        </div>

        <div class="main-content">
            <div class="mes-content">
                <div class="main-mes-top">
                    <div class="fl">
                        <a class="release-btn fl" href="{{ path('edit_file',{id:0}) }}">
                            <div class="re-width">
                                <span class="re-icon fl"></span>
                                <span class="re-text fl">发布文件</span>
                            </div>
                        </a>
                    </div>

                    <div class="fr">
                        <div class="mes-input fl">
                            <input type="text" class="keyword-input" placeholder="请输入查询关键词">
                        </div>

                        <div class="mes-input fl mes-date">
                            <span class="date-icon"></span>
                            <div class="form-group">
                                <div class="right col-xs-6 text-left">
                                    <div class="input-group">
                                        <input type="text" style="width: 114px;" class="form-control form_datetime" id="addtime" name="addtime" placeholder="开始时间">
                                        <span class="input-group-addon" id="basic-addon"><span class="glyphicon glyphicon-time" aria-hidden="true"></span></span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="mes-input fl mes-date">
                            <span class="date-icon"></span>
                            <div class="form-group">
                                <div class="right col-xs-6 text-left">
                                    <div class="input-group">
                                        <input type="text" style="width: 114px;" class="form-control form_datetime" id="addtimes" name="addtime" placeholder="结束时间">
                                        <span class="input-group-addon" id="basic-addon2"><span class="glyphicon glyphicon-time" aria-hidden="true"></span></span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <button class="mes-query-btn fl">查询</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released">文件列表</div>

                    <table class="table table-hover">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th style="width: 50%">文件标题</th>
                            <th style="text-align: center;">发布时间</th>
                            <th style="text-align: center;">操作</th>
                        </tr>
                        </thead>
                        <tbody>


                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}


{% block box %}
{% endblock %}


{% block javascript %}
<script src="{{ asset('assets/js/bootstrap-datetimepicker.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/js/bootstrap-datetimepicker.zh-CN.js') }}" type="text/javascript"></script>
    {{ parent() }}
<script type="text/javascript">
//    $(function () {
        SidebarHighlighting('6');

        // 日历
        $('.form_datetime').datetimepicker({
            minView: "month", //选择日期后，不会再跳转去选择时分秒
            language:  'zh-CN',
            format: 'yyyy-mm-dd',
            todayBtn:  1,
            autoclose: 1
        });

        // 删除
        $('body').on('click','.tab-disable', function() {

            var id = $(this).data("id");

            if(confirm('您确定要删除吗？')) {

                $.getJSON("{{ path('api_admin_delete_file') }}",{id:id},function(data){

                    if(data.errorCode == 0){

                        popStatus(1, data.message, 1,'', true);

                        // 点击页码
                        $("table tbody").empty();
                        page_times = 0;
                        getList(1);

                    } else {
                        popStatus(1, data.message, 1,'', true);
                    }

                })


            }
        });

        // 点击查询
        var search_keyword = "";
        var start_time = "";
        var end_time = "";

        $('.mes-query-btn').on('click', function() {
            search_keyword = $('.keyword-input').val();
            start_time = $('#addtime').val();
            end_time = $('#addtimes').val();

 //            if(search_keyword == "" && start_time == ''){
//                popStatus(2, '请输入或选择搜索内容', 1, '', true);
//                return;
//            }

            if (start_time != '' && end_time == '') {
                popStatus(2, '请选择结束时间', 1, '', true);
                return;
            }

            if (start_time == '' && end_time != '') {
                popStatus(2, '请选择开始时间', 1, '', true);
                return;
            }

            if (start_time > end_time) {
                popStatus(2, '开始时间不得大于结束时间', 1, '', true);
            }

            page_times = 0;
            addSearchAction(1);
        })

        // 获取文件列表
        var page_times = 0;
        function getList(page,search_keyword,start_time,end_time){
            page_times++;

            var prame = {};
            prame.id = "{{ id }}";

            prame.page = page;

            prame.search_keyword = search_keyword;
            prame.start_time = start_time;
            prame.end_time = end_time;

            $.getJSON("{{ path('api_admin_get_file_list') }}",prame,function (data) {
                $("table tbody").empty(); //3
                console.log(data);

                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }

                if(allpage == 0){
                    $(".pagination").empty();
                }

                var item = data.data.info;
                for(var i in item){
                    var html = "";

                    var edit_url = "{{ path('edit_file',{id:'784689443284'}) }}".replace("784689443284",item[i].id);

                    html += '<tr>';
                    html += '<td>'+ item[i].title +'</td>';
                    html += '<td class="center-th">'+ item[i].created_at +'</td>';
                    html += '<td class="center-th">';
                    html += '<a class="table-opera tab-edit" href="'+ edit_url +'">编辑 |</a>';
                    html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'">删除</span>';
                    html += '</td>';
                    html += '</tr>';

                    $("table tbody").append(html);

                }
            })
        }

        addSearchAction(1);  //4

        //5
        function addSearchAction(page){
            getList(page,search_keyword,start_time,end_time);
        }
//    })
</script>
{% endblock %}
